import * as React from "react";
import * as ReactDOM from "react-dom";
import { default as Editor, EditorProps } from "@qianmi/xsite-editor";
import { fromJS } from "immutable";
import { widgetCenter } from "@qianmi/x-site-core";
import * as path from "path";
import { platform } from "./manifest.json";

import view from "./src/view";
import edit from "./src/edit";

widgetCenter.registerWidget(view, {
  widgetNameSpace: "xwidget_dev"
} as any);

widgetCenter.registerWidget(edit, {
  isProxy: true,
  widgetNameSpace: "xwidget_dev"
} as any);

const outerStyle: React.CSSProperties = {
  marginLeft: 30,
  marginTop: 15
};

if (platform === "pc") {
  outerStyle.marginRight = 30;
}

const cfg: EditorProps = {
  mode: "dev",
  setting: fromJS([]),
  barInfos: fromJS([]),
  configOrder: fromJS({
    children: [
      {
        widgetNameSpace: "xwidget_dev",
        props: (edit as any).prototype.defaultProps.props
      }
    ]
  }),
  platform: "weixin",
  editorType: platform,
  loadBarList: () => Promise.resolve({}),
  getWidgetInfo: () => Promise.resolve((edit as any).prototype),
  dataCenter: {
    getResult: async () => {
      return {
        // 本地调试，示例为商城的优惠券接口
        systemConfig: {
          api_host: "http://d2c-api1.qianmi1.com",
          weixin: { couponListReqUrl: "/open_site_api/queryCouponList" }
        },
        userId: "A874677",
        systemCode: "d2cStore",
        platform: "weixin"
      };
    }
  },
  outerStyle
};

ReactDOM.render(<Editor {...cfg} />, document.getElementById("app"));
